package org.jsola.hr.query;

import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.validator.constraints.Length;
import org.jsola.core.query.BaseQuery;
import org.jsola.hr.dto.TypeAndId;
import org.jsola.orm.filter.Order;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;
import javax.validation.constraints.Max;
import javax.validation.constraints.Min;

/**
 * 政策速递
 *
 * @author zhr
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class PolicyCourierQuery extends BaseQuery {

    private static final long serialVersionUID = 1L;

    @ApiParam(value = "政策标题")
    private String title;

    @ApiParam(value = "政策级别")
    private String policyLevel;

    @ApiParam(value = "政策类型code")
    private String typeCode;

    @ApiParam(value = "用工单位Id")
    private String companyId;

    @ApiParam(value = "用工单位分组Id")
    private String companyGroupId;

    @ApiParam(value = "用工单位Id列表")
    private List<String> companyIdList;

    @ApiParam(value = "sql是否拼接union")
    private Boolean union;

    @ApiParam(value = "排序字段", allowMultiple=true, type="Order" ,example = "\"orders\": [{\"property\": \"userName\",\"desc\": false}]")
    private List<Order> orders;

    private TypeAndId TypeAndId;

    /**
     * 每页的条数
     */
    @ApiParam(value = "分页参数，每页的条数", example = "20")
    @Max(value = 1000, message = "pageSize不能大于1000")
    private Integer pageSize = 20;

    /**
     * 当前第几页
     */
    @ApiParam(value = "分页参数，第几页", example = "1")
    @Min(value = 1, message = "pageNo不能小于1")
    private Integer pageNo = 1;



    /**
     * 添加排序
     * @param propertyName 属性名
     * @param desc 是否降序
     * @return this
     */
    public PolicyCourierQuery addOrder(String propertyName, boolean desc) {
        if (CollectionUtils.isEmpty(this.orders)) {
            this.orders = new ArrayList<>();
        }
        this.orders.add(new Order(propertyName,desc));
        return this;
    }

}

